using UnityEngine;

public class DeathBringerSpellController : MonoBehaviour
{
    private Transform check;
    [SerializeField] private Vector2 boxSize = new Vector2(1.7f, 3f);
    private LayerMask layerMask => LayerMask.NameToLayer("Player");
    private CharacterStats stats;

    void Awake()
    {
        check = transform.Find("Check");
    }

    public void Setup(CharacterStats stats)
    {
        this.stats = stats;
    }

    private void AnimationTrigger()
    {
        Collider2D[] colliders = Physics2D.OverlapBoxAll(check.position, boxSize, layerMask);
        foreach (Collider2D collider in colliders)
        {
            if (collider.TryGetComponent(out Player player))
            {
                player.SetupKnockbackDirection(transform.position);
                stats.DoDamage(player.Stats);
            }
        }
    }

    public void SelfDestroy()
    {
        Destroy(gameObject);
    }

#if UNITY_EDITOR
    void OnValidate()
    {
        check = transform.Find("Check");
    }
    void OnDrawGizmos()
    {
        Gizmos.DrawWireCube(check.position, boxSize);
    }
#endif
}
